<%@ page language="java" session="true" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
double number=Math.random()*100000;
%>

  	<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/common/jquery.form.min-3.51.0.js"></script>
  	<script src="${pageContext.request.contextPath}/static/plugin/bootstrap-3.3.5/js/bootstrap.min.js"></script>

  	<script src="${pageContext.request.contextPath}/static/plugin/bootstrap-select-1.12.2/js/bootstrap-select.min.js?_t=<%=number%>"></script>


  	<script src="${pageContext.request.contextPath}/static/plugin/moment-develop/moment.min.js"></script>
  	<script src="${pageContext.request.contextPath}/static/plugin/moment-develop/local-zh-cn.js"></script>
	<script src="${pageContext.request.contextPath}/static/plugin/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js"></script>

  	 <script src="${pageContext.request.contextPath}/static/plugin/bootstrap-select-1.12.2/js/i18n/defaults-zh_CN.min.js"></script>

	<script type="text/javascript" src="${pageContext.request.contextPath}/static/plugin/toastr/toastr.min.js"></script>
  	<script type="text/javascript" src="${pageContext.request.contextPath}/static/plugin/layer-v3.0.1/layer.js"></script>
  	<script src="${pageContext.request.contextPath}/static/js/common/nifty.min.js"></script>
	<script src="${pageContext.request.contextPath}/static/plugin/toastr/toastr.min.js"></script>
  	<script src="${pageContext.request.contextPath}/static/js/common/cookie.js"></script>
  	<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/common/bootdatatable.init.js"></script>

  	<script type="text/javascript" src="${pageContext.request.contextPath}/static/plugin/bootstrap-validator/js/bootstrapValidator.js"></script>
  	<script type="text/javascript" src="${pageContext.request.contextPath}/static/plugin/bootstrap-validator/js/language/zh_CN.js"></script>

  	<![if !IE]>
  	<script type="text/javascript" src="${pageContext.request.contextPath}/static/plugin/sockjs-client/sockjs.min.js"></script>
  	<![endif]>
  	<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/common/sockinit.js"></script>
  	<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/common/plugins_app.js"></script>
  	<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/common/common.js?_t=<%=number%>"></script>
  	<script type="text/javascript">
//   	var sysId = getCookie('sysId');
	moment.locale('zh-cn');
	//项目数据初始化
	var init_project = function(){
		
		var currentProjectId = '${currentProjectId}';
		$.ajax({
		    type : "get",
		    async: false,
		    url : path+'/basic/getProjectByUser',//找到controller里相应的方法
		    success : function(data) {
		          if (data) {
		          var options = '';
		          for (var i = 0; i < data.length; i++) {
		              if (data[i].projectId == currentProjectId) {
		                  options += '<option value="'+data[i].projectId+'"style="color:#333" selected>'+data[i].projectName+'</option>';
		              } else {
		                  options += '<option value="'+data[i].projectId+'"style="color:#333" >'+data[i].projectName+'</option>';
		              }
		          }
		          $('#projectSelect').html(options);
		
		          //如果currentProjectId是下拉框中不存在的值时
		          if (currentProjectId != $('#projectSelect').val()) {
		        	  currentProjectId = $('#projectSelect').val();
		        	  changeCurrentProjectId(currentProjectId);
		          }
		          //selectpicker控件刷新
		          $('#projectSelect').selectpicker('refresh');
		      }
		    }
		   });
	};
	var changeCurrentProjectId = function(currentProjectId){
		$.ajax({
	        type : "post",
	        url :path+'/changeCurrentProjectId',//找到controller里相应的方法
	        data : {"currentProjectId":currentProjectId}, //把数组的值赋给data，把上面的param改为data,这里就能直接去掉
	        dataType : "json",//根据数据类型选择text、jason等
	        success : function(data) { 
	        	if(data == true){
	        		window.location.href=path+'/newIndex';
	        	}else{
	        		toast.error('项目切换失败！','失败提示');
	        	}
	        }
	 });
		
	};
	
	//项目切换时更新session中的值
	$("#projectSelect").change(function(){
		var currentProjectId = $('#projectSelect').val();
		changeCurrentProjectId(currentProjectId);
		//selectpicker控件刷新
	    $('#projectSelect').selectpicker('refresh');
	});
	
	
	//角色显示
	var init_role = function(){
		var roleIds = '${sessionScope.loginUser.roleIds}';
		roleIds = roleIds.substring(roleIds.indexOf('[')+1,roleIds.indexOf(']'));
		var roleIdsArr = [];
		if(roleIds.indexOf(",")>-1){
			roleIdsArr = roleIds.split(',');
		}else{
			roleIdsArr.push(roleIds);
		}
		var roleName = "";
		for(var i = 0; i < roleIdsArr.length; i++){
			if(roleIdsArr[i] == "0000"){
				roleName = "系统管理员";
				break;
			}else{
				roleName += roleName==""?"":",";
				switch(roleIdsArr[i])
				{
				case "0001":
					roleName += "管理员";
				  break;
				case "0002":
					roleName += "项目经理";
				  break;
				case "0003":
					roleName += "配置人员";
				  break;
				case "0004":
					roleName += "测试人员";
				  break;
				case "0005":
					roleName += "业务人员";
				  break;
				case "0006":
					roleName += "开发人员";
				  break;
				case "0007":
					roleName += "浏览者";
				  break;
				default:
					roleName += "无角色";
				  break;
				}
			}
		}
		$('.role-name').text(roleName);
	}
	
	if (self == top) {
	    //框架数据初始化
		init_project();
		init_role();
	}
	
	</script><%-- <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/common/interfaceUrl.js"></script> --%>